package com.hello.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hello.service.UserService;

@Controller
@RequestMapping("/login")
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/login")
	public String login() throws Exception {
		return "login";

	}

	@RequestMapping("/submit")
	public String submit(String username, String password, HttpServletRequest request) throws Exception {
		HttpSession session = request.getSession();
		// 判断密码正确性 （交给service校验） 
		String p = "p";
		if(StringUtils.isEmpty(userService.findUserByName(username))) {
			
		}else {
			 p = userService.findUserByName(username).getPassword();
		}
	
		if (username != null&&username!=""&&p!=""&&p.equals(password)) {
			session.setAttribute("username", username);
			
		}
	
		return "redirect:/list";

	}

}
